{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5]\n",
      "[[1 2]\n",
      " [3 4]]\n",
      "[[1 2]\n",
      " [5 4]]\n",
      "[[2. 2. 2.]\n",
      " [2. 2. 2.]]\n",
      "[[0.5 0.5 0.5]\n",
      " [0.5 0.5 0.5]]\n",
      "[[3. 3. 3.]\n",
      " [3. 3. 3.]]\n",
      "[[-1. -1. -1.]\n",
      " [-1. -1. -1.]]\n",
      "[[2. 3. 4.]\n",
      " [5. 6. 7.]]\n",
      "[[ 0. -1. -2.]\n",
      " [-3. -4. -5.]]\n",
      "[[1. 2. 3.]\n",
      " [4. 5. 6.]]\n",
      "[[1.         0.5        0.33333333]\n",
      " [0.25       0.2        0.16666667]]\n"
     ]
    }
   ],
   "source": [
    "# 构造矩阵\n",
    "data1 = np.array([1,2,3,4,5])\n",
    "print(data1)\n",
    "data2 = np.array([[1,2],[3,4]])\n",
    "print(data2)\n",
    "# 修改矩阵第1行和第0列\n",
    "data2[1,0] = 5\n",
    "print(data2)\n",
    "# 矩阵基本运算\n",
    "data3 = np.ones([2,3])\n",
    "# 与常数进行基本运算(所有元素与常数做相应的运算)\n",
    "print(data3*2)\n",
    "print(data3/2)\n",
    "print(data3+2)\n",
    "print(data3-2)\n",
    "# 与矩阵进行基本运算(对应元素分别做计算)\n",
    "data4 = np.array([[1,2,3],[4,5,6]])\n",
    "print(data3+data4)\n",
    "print(data3-data4)\n",
    "print(data3*data4)\n",
    "print(data3/data4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5,) (2, 2)\n"
     ]
    }
   ],
   "source": [
    "# 矩阵维度\n",
    "print(data1.shape,data2.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0. 0.]\n",
      " [0. 0. 0.]]\n",
      "[[1. 1. 1.]\n",
      " [1. 1. 1.]]\n"
     ]
    }
   ],
   "source": [
    "# 空矩阵\n",
    "print(np.zeros([2,3]))\n",
    "# 单位矩阵\n",
    "print(np.ones([2,3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
